<template>
	<view class="">
		<view class="information">
			<view class="title">基本信息</view>
			<view class="information_message">
				<view class="information_infor">
					<view class="information_infor_l">头像</view>
					<view class="information_infor_l information_infor_r"><image :src="runinfo.Logo"></image></view>
				</view>
				<view class="information_infor">
					<view class="information_infor_l">跑团名称</view>
					<view class="information_infor_l information_infor_r">{{ runinfo.Title }}</view>
				</view>
				<view class="information_infor">
					<view class="information_infor_l">团长</view>
					<view class="information_infor_l information_infor_r">{{ runinfo.Contacter }}</view>
				</view>
				<view class="information_infor">
					<view class="information_infor_l">城市</view>
					<view class="information_infor_l information_infor_r">{{ runinfo.City }}</view>
				</view>
				<view class="information_infor">
					<view class="information_infor_l">活动地址</view>
					<view class="information_infor_l information_infor_r">{{ runinfo.Address }}</view>
				</view>
				<view class="information_infor">
					<view class="information_infor_l">上级跑团</view>
					<view class="information_infor_l information_infor_r">{{ runinfo.Title }}</view>
				</view>
			</view>
			<view class="title">
				认证信息
				<view class="no_authe" v-if="auther_state">未认证</view>
			</view>
			<view class="information_message" v-if="authentication">
				<view class="information_infor">
					<view class="information_infor_l">认证类型</view>
					<view class="information_infor_l information_infor_r" v-if="authentication.cation_type == 1">个人</view>
					<view class="information_infor_l information_infor_r" v-else-if="authentication.cation_type == 2">企业</view>
					<view class="information_infor_l information_infor_r" v-else>组织</view>
				</view>
				<view class="information_infor">
					<view class="information_infor_l">认证主体</view>
					<view class="information_infor_l information_infor_r" v-if="authentication.cation_type == 1">{{ authentication.user_name }}</view>
					<view class="information_infor_l information_infor_r" v-else-if="authentication.cation_type == 2">{{ authentication.company_name }}</view>
					<view class="information_infor_l information_infor_r" v-else>{{ authentication.organize_name }}</view>
				</view>
			</view>
			<!-- 退出跑团 -->
			<view class="goout" v-if="user_run.Id && colonelFlag == false && user_run.Title == runinfo.Title" @tap="quit">退出跑团</view>
			<view class="goout" v-if="user_run.Id && colonelFlag == true && user_run.Title == runinfo.Title" @tap="quit_t">解散跑团</view>
		</view>
		<!-- loading 遮罩层 -->
		<loading v-if="loadflag"></loading>
		<navigation></navigation>
	</view>
</template>

<script>
import loading from '@/components/loading/loading.vue';
import navigation from '@/components/navigation/navigation.vue';
export default {
	components: { loading, navigation },
	data() {
		return {
			loadflag: true,
			runinfo: {},
			club_id: '',
			authentication: {},
			auther_state: '',
			user_run: {},
			colonel: {},
			colonelFlag: false
		};
	},
	mounted() {
		this.getrunInfo();
		this.getCation();
		this.getmemberList();
	},
	onLoad(options) {
		this.club_id = options.id;
	},
	methods: {
		// 获取跑团基本信息
		getrunInfo() {
			this.ajax('club/clubInfo', {
				data: {
					id: this.club_id
				},
				success: res => {
					if(res.msg.Logo) {
						res.msg.Logo = res.msg.Logo.replace('http:', 'https:');
						var reg = RegExp('/?x-oss-process=image/');
						if( !reg.test(res.msg.Logo)) {
							uni.getImageInfo({
								src: res.msg.Logo,
								success: function(image) {
									if (image.width > image.height) {
										res.msg.Logo = res.msg.Logo + '?x-oss-process=image/rotate,0';
									}
								}
							});
						}
					}
					//  // console.log (res);
					this.runinfo = res.msg;
					this.getuserinfo();
				}
			});
		},
		// 获取认证信息
		getCation() {
			this.ajax('club/clubCation', {
				data: {
					club_id: this.club_id
				},
				success: res => {
					//  // console.log (res);
					this.authentication = res.msg;
					if (res.msg == null) {
						this.auther_state = '未认证';
					}
					this.loadflag = false;
				}
			});
		},
		// 获取会员信息
		getuserinfo() {
			this.ajax('user/userInfo', {
				success: res => {
					 // console.log (res.msg.Id);
					 // console.log (this.colonel.Id);
					this.user_run = res.msg.club_info;
					if (this.colonel.Id == res.msg.Id) {
						this.colonelFlag = true;
					} else {
						this.colonelFlag = false;
					}
				}
			});
		},
		getmemberList() {
			var _this = this;
			this.ajax('club/clubUser', {
				data: {
					club_id: _this.club_id
				},
				success: function(res) {
					//  // console.log (res);
					var list = res.msg.data;
					var newList = [];
					for (var attr in list) {
						newList = newList.concat(list[attr]);
					}
					var regimental = {};
					var admin = [];
					//  // console.log (_this)
					 // console.log (newList);
					newList.forEach(e => {
						e.cityName = e.MemberName;
						if (e.ClubRole == 9) {
							regimental = e;
							_this.colonel = e;
						} else if (e.ClubRole == 5) {
							admin = admin.concat(e);
						}
					});
					 // console.log (regimental);
				}
			});
		},
		quit() {
			var that = this;
			uni.showModal({
				title: '温馨	提示',
				content: '您确定要退出跑团吗？',
				success: function(res) {
					if (res.confirm) {
						that.ajax('club/outClub', {
							data: {
								club_id: that.club_id
							},
							success: res => {
								 // console.log (res);
								if (!res.code) {
									that.toast(res.msg);
								} else {
									uni.reLaunch({
										url: '/pages/discover/discover'
									});
								}
							}
						});
					} else if (res.cancel) {
						 // console.log ('用户点击取消');
					}
				}
			});
		},
		quit_t() {
			var that = this;
			uni.showModal({
				title: '温馨	提示',
				content: '您确定要解散跑团吗？',
				success: function(res) {
					if (res.confirm) {
						that.ajax('club/disClub', {
							data: {
								club_id: that.club_id
							},
							success: res => {
								 // console.log (res);
								 // console.log (res);
								if (!res.code) {
									this.toast(res.msg);
								} else {
									uni.reLaunch({
										url: '/pages/index/index'
									});
								}
							}
						});
					} else if (res.cancel) {
						 // console.log ('用户点击取消');
					}
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
page {
	background-color: #ffffff;
}
.title {
	width: 100%;
	height: 85upx;
	background-color: #f2f2f2;
	padding-left: 30upx;
	box-sizing: border-box;
	color: #999;
	font-size: 28upx;
	line-height: 85upx;
	position: relative;
	.no_authe {
		position: absolute;
		right: 30upx;
		top: 50%;
		transform: translateY(-50%);
	}
}
.information_message {
	background-color: #ffffff;
	padding: 0 30upx;
	box-sizing: border-box;
}
.information_infor {
	width: 100%;
	height: 96upx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 2upx solid #e1e1e1;
	.information_infor_l {
		color: #333;
		font-size: 28upx;
		image {
			width: 62upx;
			height: 62upx;
			border-radius: 50%;
		}
	}
	.information_infor_r {
		width: 520upx;
		text-align: right;
	}
}
.information_infor:last-child {
	border-bottom: 0;
}
.goout {
	position: fixed;
	bottom: 0;
	height: 80upx;
	width: 100%;
	// width: calc(100% - 60upx);
	background-color: #8838d2;
	font-size: 28upx;
	color: #ffffff;
	// border-radius:40upx;
	text-align: center;
	line-height: 80upx;
	margin: 0 auto;
	margin-top: 30upx;
}
</style>
